    //
//  WBHomeViewController.swift
//  Weibo
//
//  Created by 李磊 on 2017/6/5.
//  Copyright © 2017年 李磊www. All rights reserved.
//

import UIKit
    
private let cellId = "cellId"

class WBHomeViewController: WBBaseViewController {
    
    lazy var statusList = [String]()
    
    override func loadData() {
        
        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()+1) {
            for i in 0..<30 {
                if self.isPullup {//上拉刷新
                    self.statusList.append("上拉\(i)")
                }else{
                    self.statusList.insert(i.description, at: 0)
                }
            }
            
            // 结束刷新
            self.refreshControl?.endRefreshing()
            
            // 恢复上拉刷新的标记
            self.isPullup = false
            
            // 刷新表格
            self.tableView?.reloadData()
            
            
        }
        
        
    }
    

    override func viewDidLoad() {
        super.viewDidLoad()
       
    }
    
    func leftAction() {
        let vc = WBBaseViewController()
        
        navigationController?.pushViewController(vc, animated: true)
        
    }
    
    

}

// MARK: - UI
extension WBHomeViewController {
    
    override func setupUI() {
        super.setupUI()
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "好友", target: self, action: #selector(leftAction))
        
        tableView?.register(UITableViewCell.self, forCellReuseIdentifier: cellId)
    }
    
}

    
extension WBHomeViewController {

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return statusList.count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath)
        
        cell.textLabel?.text = statusList[indexPath.row]
        
        return cell
        
    }

}

